﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Lottery.Client.SL.Util
{
    public class Screen
    {
        public static void GetMonitorResolutionAsync(Action<int, int> callback)
        {
            if (!Application.Current.HasElevatedPermissions)
            {
                throw new NotSupportedException("This method requires elevated permissions.");
            }

            var content = Application.Current.Host.Content;
            var dispatcher = App.Current.MainWindow.Dispatcher;

            if (!content.IsFullScreen)
            {
                dispatcher.BeginInvoke(() =>
                {
                    content.IsFullScreen = true;

                    if (!content.IsFullScreen)
                    {
                        callback(0, 0);
                        return;
                    }

                    int width = (int)Math.Round(content.ActualWidth);
                    int height = (int)Math.Round(content.ActualHeight);

                    content.IsFullScreen = false;

                    callback(width, height);
                });
            }
            else
            {
                dispatcher.BeginInvoke(() =>
                {
                    int width = (int)Math.Round(content.ActualWidth);
                    int height = (int)Math.Round(content.ActualHeight);
                    callback(width, height);
                });
            }
        }
    }
}
